<?php

use yii\grid\GridView;
use common\helpers\Html;
use common\helpers\ImageHelper;

$this->title = '个人管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header">
                <h3 class="box-title"><?= $this->title; ?></h3>
                <div class="box-tools">
                    <?= Html::create(['edit'])?>
                </div>
            </div>
            <!-- /.box-header -->
            <div class="box-body table-responsive">
                <?= GridView::widget([
                    'dataProvider' => $dataProvider,
                    'filterModel' => $searchModel,
                    //重新定义分页样式
                    'tableOptions' => ['class' => 'table table-hover'],
                    'columns' => [
                        [
                            'class' => 'yii\grid\SerialColumn',
                            'visible' => false, // 不显示#
                        ],
                        'id',
                        [
                                'attribute'=>'name',
                                'value'=>function($model){//实现 添加a标签
                                    return Html::a($model->name,'http://www.baidu.com');
                                },
                                'format'=>'raw'
                        ],
                        [
                            'attribute' => 'img',
                            'value' => function ($model) {
                            //return Html::a('点击查看图片',$model -> img,['target'=>'_blank']);

                                return Html::img(ImageHelper::defaultHeaderPortrait(Html::encode($model->img)),
                                    [
                                        'class' => 'img-circle rf-img-md img-bordered-sm',
                                        //'style'=>'width:100px',
                                    ]);
                            },
                            'filter' => false,
                            'format' => 'raw',
                        ],
                        [
                            'attribute' => 'sex',
                            'value'=>function($model){
                                if($model->sex==1){
                                    return '男';
                                }else{
                                    return '女';
                                }
                            },
                            'filter' => [''=>'全部','1'=>'男','2'=>'女'],//实现下拉框搜索//'filter' => false, //不显示搜索框
                            //'format' => 'raw' //使用a标签时 不加会a标签不解析
                        ],
                        [
                            'attribute' => 'class',
                            'value' => 'cla.class_name',
                            'filter' => Html::activeDropDownList($searchModel, 'cla_id',
                                $claList, [
                                    'prompt' => '全部',
                                    'class' => 'form-control'
                                ]
                            ),

                        ],
                        [
                                'label'=>'自定义列',
                                'value'=>function($key,$model,$url){
                                    return '哈哈';
                                }
                        ],
                        [
                            'label'=> '创建时间',
                            'attribute' => 'created_at',
                            //'filter' => false, //不显示搜索框
                            'format' => ['date', 'php:Y-m-d H:i:s'],
                        ],
                        [
                            'header' => "操作",
                            'class' => 'yii\grid\ActionColumn',
                            'template'=> '{edit} {status} {delete}',
                            'buttons' => [
                                'edit' => function ($url, $model, $key) {
                                    return Html::edit(['edit', 'id' => $model->id]);
                                },
                                'delete' => function ($url, $model, $key) {
                                    return Html::delete(['delete', 'id' => $model->id]);
                                },
                            ],
                        ],
                    ],
                ]); ?>
                <!-- /.box-body -->
            </div>
            <!-- /.box -->
        </div>
    </div>
</div>